//! Copyright 2012 Xicut Technology, Inc.
//! All rights reserved
//!
#include "Config.h"
#include "SIM900AppCommand.h"

cSIM900AppCommand cSIM900AppCommand::s_AllocationPool[ cConfig::SIM900_SMS_POOL_SIZE ];
U32               cSIM900AppCommand::s_CurAllocIndex;

cFIFO             cSIM900AppCommand::s_SendFIFO;
U32               cSIM900AppCommand::s_SendFIFO_Storage[ cConfig::SIM900_SEND_POOL_SIZE ];
cFIFO             cSIM900AppCommand::s_SendStatusFIFO;
U32               cSIM900AppCommand::s_SendStatusFIFO_Storage[ cConfig::SIM900_SEND_POOL_SIZE ];
cFIFO             cSIM900AppCommand::s_ReceiveFIFO;
U32               cSIM900AppCommand::s_ReceiveFIFO_Storage[ cConfig::SIM900_RECEIVE_POOL_SIZE ];
cFIFO             cSIM900AppCommand::s_ReceiveStatusFIFO;
U32               cSIM900AppCommand::s_ReceiveStatusFIFO_Storage[ cConfig::SIM900_RECEIVE_POOL_SIZE ];


void cSIM900AppCommand::Init_Reset()
{
    s_CurAllocIndex = 0;

    s_SendFIFO.Init(s_SendFIFO_Storage, cConfig::SIM900_SEND_POOL_SIZE);
    s_SendStatusFIFO.Init(s_SendStatusFIFO_Storage, cConfig::SIM900_SEND_POOL_SIZE);
    s_ReceiveFIFO.Init(s_ReceiveFIFO_Storage, cConfig::SIM900_RECEIVE_POOL_SIZE);
    s_ReceiveStatusFIFO.Init(s_ReceiveStatusFIFO_Storage, cConfig::SIM900_RECEIVE_POOL_SIZE);
}

SIM900AppCommandHandle cSIM900AppCommand::Alloc()
{
    return( s_AllocationPool[ s_CurAllocIndex++ ].GetHandle() );
}

cSIM900AppCommand* cSIM900AppCommand::GetPointer( SIM900AppCommandHandle Handle )
{
    return( reinterpret_cast<cSIM900AppCommand*>( Handle._ ) );
}

SIM900AppCommandHandle cSIM900AppCommand::GetHandle()
{
    SIM900AppCommandHandle handle;
    handle._ = reinterpret_cast<U32>( this );
    return( handle );
}
